package Z.dailyExercise._0107;

public class _704_二分查找 {
    public int search(int[] nums, int target) {
        return Binarysearch(nums,target,0 ,nums.length-1);

    }

    public int Binarysearch(int[] nums, int target,int low,int high) {

        if (low>high || target<nums[0] || target>nums[nums.length-1]){
            return -1;
        }

        if (nums[high]==nums[low] ){
            if (nums[low] == target){
                return low;
            }else {
                return -1;
            }
        }
        int mid = low + (high-low)*(target-nums[low])/(nums[high]-nums[low]);

        if (target<nums[mid]){
            return Binarysearch(nums,target,low,mid-1);
        }else if (target>nums[mid]){
            return Binarysearch(nums,target,mid+1,high);
        }else {
            return mid;
        }

    }
}
